defmodule GiomWeb.PtransControllerTest do
  use GiomWeb.ConnCase

  alias Giom.Accounting

  @create_attrs %{date: "2010-04-17 14:00:00.000000Z"}
  @update_attrs %{date: "2011-05-18 15:01:01.000000Z"}
  @invalid_attrs %{date: nil}

  def fixture(:ptrans) do
    {:ok, ptrans} = Accounting.create_ptrans(@create_attrs)
    ptrans
  end

  describe "index" do
    test "lists all ptrans", %{conn: conn} do
      conn = get conn, ptrans_path(conn, :index)
      assert html_response(conn, 200) =~ "Listing Ptrans"
    end
  end

  describe "new ptrans" do
    test "renders form", %{conn: conn} do
      conn = get conn, ptrans_path(conn, :new)
      assert html_response(conn, 200) =~ "New Ptrans"
    end
  end

  describe "create ptrans" do
    test "redirects to show when data is valid", %{conn: conn} do
      conn = post conn, ptrans_path(conn, :create), ptrans: @create_attrs

      assert %{id: id} = redirected_params(conn)
      assert redirected_to(conn) == ptrans_path(conn, :show, id)

      conn = get conn, ptrans_path(conn, :show, id)
      assert html_response(conn, 200) =~ "Show Ptrans"
    end

    test "renders errors when data is invalid", %{conn: conn} do
      conn = post conn, ptrans_path(conn, :create), ptrans: @invalid_attrs
      assert html_response(conn, 200) =~ "New Ptrans"
    end
  end

  describe "edit ptrans" do
    setup [:create_ptrans]

    test "renders form for editing chosen ptrans", %{conn: conn, ptrans: ptrans} do
      conn = get conn, ptrans_path(conn, :edit, ptrans)
      assert html_response(conn, 200) =~ "Edit Ptrans"
    end
  end

  describe "update ptrans" do
    setup [:create_ptrans]

    test "redirects when data is valid", %{conn: conn, ptrans: ptrans} do
      conn = put conn, ptrans_path(conn, :update, ptrans), ptrans: @update_attrs
      assert redirected_to(conn) == ptrans_path(conn, :show, ptrans)

      conn = get conn, ptrans_path(conn, :show, ptrans)
      assert html_response(conn, 200)
    end

    test "renders errors when data is invalid", %{conn: conn, ptrans: ptrans} do
      conn = put conn, ptrans_path(conn, :update, ptrans), ptrans: @invalid_attrs
      assert html_response(conn, 200) =~ "Edit Ptrans"
    end
  end

  describe "delete ptrans" do
    setup [:create_ptrans]

    test "deletes chosen ptrans", %{conn: conn, ptrans: ptrans} do
      conn = delete conn, ptrans_path(conn, :delete, ptrans)
      assert redirected_to(conn) == ptrans_path(conn, :index)
      assert_error_sent 404, fn ->
        get conn, ptrans_path(conn, :show, ptrans)
      end
    end
  end

  defp create_ptrans(_) do
    ptrans = fixture(:ptrans)
    {:ok, ptrans: ptrans}
  end
end
